/*
 * Created on 2006-02-18
 */
package dk.aiszone.lang.comparatorfactory;

import java.util.Iterator;

import dk.aiszone.lang.autosource.formatter.JavaFormatterImpl;
import dk.aiszone.lang.autosource.generatorobjects.Class;
import dk.aiszone.lang.autosource.generatorobjects.GenericClass;
import dk.aiszone.lang.autosource.generatorobjects.Import;

/**
 * Extension of the <code>JavaFormatterImpl</code> overriding the <code>toJava(Class)</code> method.<br>
 * Instead of writing imports to the file, all <code>Classes</code> are written using their full package.
 * 
 * @author <a href="mailto:ais@mail.dk">Ais</a>
 */
public class NoImportJavaFormatter extends JavaFormatterImpl {

    @Override
    public String toJava(Class _class) {
        assert _class.isVoid() || _class.isConstructor() || _class.getClassName() != null : "PackageName was null";

        if (_class.isVoid()) {
            return "void";
        } else if (_class.isConstructor()) {
            return "";
        }

        StringBuffer buf = new StringBuffer();

        String className = _class.getPackageName();
        if (className != null) {
            buf.append(className);
        }

        if (_class.isArray()) {
            buf.append("[]");
        }

        if (_class.getGenerics() != null && !_class.getGenerics().isEmpty()) {
            buf.append("<");
            for (Iterator<GenericClass> iter = _class.getGenerics().iterator(); iter.hasNext();) {
                buf.append(toJava(iter.next()));
                if (iter.hasNext()) {
                    buf.append(", ");
                }
            }
            buf.append(">");
        }

        return buf.toString();
    }

    @Override
    public String toJava(Import _import) {
        return "";
    }
}